﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using Microsoft.Practices.Prism.Events;
using RZD_maps.Infrastructure;
using RZD_maps.Modules.Ribbon.Model;

namespace RZD_maps.Modules.Ribbon.ViewModel
{
    public class RibbonViewModel
    {
        private IRibbonView _view;

        private IEventAggregator eventAggregator;

        public RibbonViewModel(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
            rzd_model.ViewModel = this;
        }

        public void OnTransferControlData(RZD_mapsEvent e)
        {
            TransferControlData(this, e);
        }

        void TransferControlData(object sender, EventArgs e)
        {
            RZD_mapsEvent evnt = e as RZD_mapsEvent;
            if (evnt == null) return;
            ControlDataItem controlData = new ControlDataItem();
            controlData.command = evnt.command;
            eventAggregator.GetEvent<ControlDataEvent>().Publish(controlData);
        }


        public IRibbonView View
        {
            get
            {
                return _view;
            }
            set
            {
                _view = value;
                _view.ControlData += TransferControlData;
            }
        }

    }
}
